import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

/// 采购订单
class HttpPurchaseOrderService {
  /// 采购订单列表
  static Future<Response> purchaseOrdersList(int page,
      {String status, int issue_to, String keyword}) {
    return BaseConfig.httpBase.get('/api/purchase_orders', {
      'page': page,
      'status': status,
      'issue_to': issue_to,
      'keyword': keyword,
    });
  }

  /// 采购进行配送
  static Future<Response> deliver(int id) {
    return BaseConfig.httpBase.putJson('/api/purchase_orders/$id/deliver', {});
  }

  /// 创建采购订单
  static Future<Response> createPurchaseOrders({
    int contactId,
    String number,
    String issued_at,
    String delivery_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    double total,
    String notes,
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_line_2,
    String address_unit,
    List item,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/purchase_orders', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issued_at,
      "delivery_at": delivery_at,
      "currency_code": currency_code,
      "subtotal": subtotal,
      'address_unit': address_unit,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "total": total,
      "notes": notes,
      "address_country": address_country,
      "address_city": address_city,
      "address_postal_code": address_postal_code,
      "address_line_1": address_line_1,
      "address_line_2": address_line_2,
      "items": item,
      'attachment_ids': attachment_ids,
    });
  }

  /// 显示采购订单
  static Future<Response> showPurchaseOrders(int purchaseOrdersId) {
    return BaseConfig.httpBase
        .get('/api/purchase_orders/$purchaseOrdersId', {});
  }

  /// 删除采购订单
  static Future<Response> deletePurchaseOrders(int purchaseOrdersId) {
    return BaseConfig.httpBase
        .deleteJson('/api/purchase_orders/$purchaseOrdersId', {});
  }

  /// 更新采购订单
  static Future<Response> updatePurchaseOrders(
    int purchaseOrdersId, {
    int contactId,
    String number,
    String issued_at,
    String delivery_at,
    String currency_code,
    double subtotal,
    double exclusive_tax_amount,
    double inclusive_tax_amount,
    double total,
    String notes,
    String address_country,
    String address_city,
    String address_postal_code,
    String address_line_1,
    String address_line_2,
    String address_unit,
    List item,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase
        .putJson('/api/purchase_orders/$purchaseOrdersId', {
      "contact_id": contactId,
      "number": number,
      "issued_at": issued_at,
      "delivery_at": delivery_at,
      "currency_code": currency_code,
      'address_unit': address_unit,
      "subtotal": subtotal,
      "exclusive_tax_amount": exclusive_tax_amount,
      "inclusive_tax_amount": inclusive_tax_amount,
      "total": total,
      "notes": notes,
      "address_country": address_country,
      "address_city": address_city,
      "address_postal_code": address_postal_code,
      "address_line_1": address_line_1,
      "address_line_2": address_line_2,
      "items": item,
      'attachment_ids': attachment_ids,
    });
  }
}
